#include <dbg.h>
#include <gtest/gtest.h>

using namespace std;

class Solution {
public:
    int countSymmetricIntegers(int low, int high) {
        int count = 0;
        for (int i = low; i <= high; i++) {
            if (isSymmetric(i)) {
                ++count;
            }
        }
        return count;
    }

private:
    bool isSymmetric(int num) {
        int digitCount = 0;
        int temp = num;
        while (temp != 0) {
            digitCount++;
            temp /= 10;
        }
        if (digitCount % 2 != 0) {  // 奇数位数，无法对称
            return false;
        }

        int half = digitCount / 2;
        int sum1 = 0;
        int sum2 = 0;
        for (int i = 0; i < digitCount; ++i) {
            int digit = num % 10;
            if (i < half) {
                sum2 += digit;
            } else {
                sum1 += digit;
            }
            num /= 10;
        }

        return sum1 == sum2;
    }
};

TEST(TEST1, countSymmetricIntegers) {
    Solution s;
    EXPECT_EQ(s.countSymmetricIntegers(1, 100), 9);
}

TEST(TEST2, countSymmetricIntegers) {
    Solution s;
    EXPECT_EQ(s.countSymmetricIntegers(1200, 1230), 4);
}

int main(int argc, char** argv) {
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}